//https://www.luogu.com.cn/problem/P1019
#include<iostream>
#include<string>
#include<vector>
#include<array>
using std::string;

std::vector<string> ALL;

//n≤20
struct graph{
	int N;
	int E[20][20];
	int DFS(int from);
	int __DFS(int from,std::array<char,20> used,int grade,int current);
};

void print(graph& G) {
	using std::cout;
	for(int from = 0;from < G.N;++from) {
		for(int to = 0;to < G.N;++to) {
			cout << G.E[from][to] << ' ';
		}
		cout << '\n';
	}
}
int graph::DFS(int from){
	std::cout<<"begin:"<<ALL[from]<<'\n';
	std::array<char,20> used;
	for(int i=0;i<N;++i){used[i]=0;}
	used[from]+=1;
	int res=ALL[from].size();
	int res_latter=0;;
	for(int to=0;to<N;++to){
		if(E[from][to]!=-1){
			std::cout<<ALL[from]<<"--->"<<ALL[to]<<'\n';
			int temp=__DFS(to,used,1,res+E[from][to]);
			res_latter=std::max(res_latter,temp);
		}
	}
	return res_latter;
}
int graph::__DFS(int from,std::array<char,20> used,const int grade,int current){
	used[from]+=1;
	int res=0;
	for(int to=0;to<N;++to){
		if(E[from][to]!=-1&&used[to]<2){
			for(int i=0;i<grade;++i){std::cout<<'\t';}
			std::cout<<'['<<current<<']';
			std::cout<<ALL[from]<<"--->"<<ALL[to]<<'\n';
			int temp=E[from][to]+__DFS(to,used,grade+1,current+E[from][to]);
			
			res=std::max(res,temp);
		}
	}
	return res+current;
}



int deriv_length(const string& from,const string& to){
	int res=-1;

	auto f_it=from.end()-1,t_it=to.begin(),t_it_to=to.begin()+1;

	for(;f_it!=from.begin()&&t_it_to!=to.end();--f_it,++t_it_to){
		std::string_view sub1(f_it.base(),from.end()-f_it);
		std::string_view sub2(to.c_str(),t_it_to-to.begin());
		if(sub1==sub2){
			res=to.end()-t_it_to;
		}
	}
	return res;
}




int main(){
	using namespace std;
	int N;
	cin>>N;
	ALL.resize(N);
	for(int i=0;i<N;++i){
		cin>>ALL[i];
	}
	char begin_with;
	cin>>begin_with;
	graph G;
	G.N=N;
	for(int from=0;from<N;++from){
		for(int to=0;to<N;++to){
			
			G.E[from][to]=deriv_length(ALL[from],ALL[to]);
		}
	}
	print(G);
	int res=0;
	for(int from=0;from<N;++from){
		if(ALL[from][0]==begin_with){
			res=max(res,G.DFS(from));
		}
	}
	cout<<res;
	return 0;
}



